package com.danco.planner.viewcontrollers;

import com.danco.planner.services.CoursesListService;
import com.danco.planner.supportclasses.enumeration.IEventType;
import com.danco.planner.supportclasses.enumeration.PlannerEventType;
import com.danco.planner.view.builders.AbstractViewsBuilder;
import com.danco.planner.view.builders.ConsoleViewsBuilder;
import com.danco.planner.view.core.AbstractButton;
import com.danco.planner.view.core.View;

public class CoursesVC extends AbstractPlannerVC {

	public CoursesVC() {
		super();
	}
	public CoursesVC(View view) {
		super(view);
	}
	public CoursesVC(View view, String title) {
		super(view, title);
	}

	@Override
	protected void initAllOtherSubviews() {
		
		AbstractViewsBuilder builder = new ConsoleViewsBuilder();
		
		AbstractButton sortByNameBtn = builder.buildButton("Sort by name", "sbName", PlannerEventType.sortByName);
		AbstractButton sortByStartDate = builder.buildButton("Sort by start date", "sbSDate", PlannerEventType.sortByStartDate);
		AbstractButton sortBySection = builder.buildButton("Sort by section", "sbSection", PlannerEventType.sortBySection);
		AbstractButton sortBySpeaker = builder.buildButton("Sort by speaker", "sbSpeaker", PlannerEventType.sortBySpeaker);
		AbstractButton sortByStudentsCount = builder.buildButton("Sort by students count", "sbStudCount", PlannerEventType.sortByStudentsCount);
		
		sortByNameBtn.addListener(this);
		sortByStartDate.addListener(this);
		sortBySection.addListener(this);
		sortBySpeaker.addListener(this);
		sortByStudentsCount.addListener(this);
		
		baseView.addSubviews(sortByNameBtn,sortBySection,sortByStartDate,sortBySpeaker,sortByStudentsCount);	
	}
	@Override
	protected String getMainContent() {
		return CoursesListService.getCoursesListDescription();
	}
	
	@Override
	public void handleAction(Object arg0, IEventType arg1) {
		
		super.handleAction(arg0, arg1);
		
		if (arg1 == PlannerEventType.sortByName) {
			sortByName();
		}
		else if (arg1 == PlannerEventType.sortByStartDate) {
			sortByStartDate();
		}
		else if (arg1 == PlannerEventType.sortBySection) {
			sortBySection();
		}
		else if (arg1 == PlannerEventType.sortBySpeaker) {
			sortBySpeaker();
		}
		else if (arg1 == PlannerEventType.sortByStudentsCount) {
			sortByStudentsCount();
		}	
	}
	
	private void sortByName() {
		this.contentLabel.setText(CoursesListService.getCoursesListDescriptionSortedByName());
	}
	private void sortByStartDate() {
		this.contentLabel.setText(CoursesListService.getCoursesListDescriptionSortedByStartDate());
	}
	private void sortBySection() {
		this.contentLabel.setText(CoursesListService.getCoursesListDescriptionSortedBySection());
	}
	private void sortBySpeaker() {
		this.contentLabel.setText(CoursesListService.getCoursesListDescriptionSortedBySpeaker());
	}
	private void sortByStudentsCount() {
		this.contentLabel.setText(CoursesListService.getCoursesListDescriptionSortedByStudentsCount());
	}
}
